package com.youhome.report.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import java.util.Locale;

/**
 * Created by chen365 on 2018/08/29. WebMvcConfigurerAdapter
 */
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

    /** 静态资源处理 **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //和页面有关的静态目录都放在项目的static目录下
        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
        registry.addResourceHandler("/img/**").addResourceLocations("classpath:/static/img/");
        // 上传的图片在D盘下的 chart 目录下，访问路径如：http://localhost:8081/chart/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
        // 其中chart表示访问的前缀。"file:/alldata/chart"是文件真实的存储路径
        registry.addResourceHandler("/chart/**").addResourceLocations("file:/alldata/chart/");
        registry.addResourceHandler("/google_static_map/**").addResourceLocations("file:/alldata/google_static_map/");
    }

    @Bean
    public LocaleResolver localeResolver() {
        return  new MyLocaleResolver();
    }
}
